﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace FooFun.DataElements.Dtos
{
    public class DataRowDataElement : DataElement
    {
        DataRow row;

        public DataRowDataElement(DataRow row)
        {
            this.row = row;
        }

        #region IDataElement 成员

        public override object Value
        {
            get
            {
                return row;
            }
            set
            {
                row = (DataRow)value;
            }
        }

        public override IDataElement this[string attrName]
        {
            get
            {
                return new ObjectDataElement(row[attrName]);
            }
            set
            {
                row[attrName] = value;
            }
        }

        public override bool IsEmpty
        {
            get
            {
                foreach (DataColumn col in row.Table.Columns)
                {
                    if (!row.IsNull(col))
                    {
                        return false;
                    }
                }
                return true;
            }
        }

        #endregion
    }
}
